package com.itheima.servletContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//获取ServletContext对象
public class ServletDemo09 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取ServletContext对象
        ServletContext servletContext = this.getServletContext();//this表示ServletDemo09的实例对象
        ServletContext servletContext1 = req.getServletContext();
        ServletContext servletContext2 = this.getServletConfig().getServletContext();
        ServletContext servletContext3 = getServletContext();
        ServletContext servletContext4 = req.getSession().getServletContext();
        servletContext.setAttribute("hello","body");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
